
cmake_minimum_required (VERSION 2.6)

project("kcaldav")

find_package(KDE4 REQUIRED)
find_package(Qt4 REQUIRED)
include(KDE4Defaults)
include(KDE4Macros)
include(FindKDE4Internal)
include(FindKdepimLibs)
include(FindGLIB2)
include(FindCURL)

include_directories(
    ${KDE4_INCLUDES}
    ${QT_INCLUDES}
    ${GLIB2_INCLUDE_DIR}
)

########### set variables #############

# Do not use RPATH, since dependent libraries are in /usr/lib
set(CMAKE_SKIP_RPATH TRUE)

add_definitions(-DKDE_DEFAULT_DEBUG_AREA=5650)  # kresources debug area

if(KCALDAV_DEBUG)
    set(CMAKE_BUILD_TYPE Debug)
    add_definitions(-DKCALDAV_DEBUG)  # enables debug output
endif()

########### next target ###############

set(kcal_caldav_LIB_SRCS    resource.cpp 
                            config.cpp 
                            configwidgets.cpp
                            preferences.cpp 
                            job.cpp
                            reader.cpp 
                            writer.cpp 
)

kde4_add_kcfg_files(kcal_caldav_LIB_SRCS prefsskel.kcfgc)

kde4_add_library(kcal_caldav SHARED ${kcal_caldav_LIB_SRCS})

# add imported target
add_library(kcaldav_caldav_lib STATIC IMPORTED)
# point the imported target at the real file
set_target_properties(kcaldav_caldav_lib PROPERTIES IMPORTED_LOCATION libcaldav.a)

target_link_libraries(kcal_caldav  
                        ${KDE4_KDECORE_LIBS} 
                        ${KDEPIMLIBS_KCAL_LIBS} 
                        ${KDEPIMLIBS_KRESOURCES_LIBS} 
                        kcaldav_caldav_lib 
                        ${CURL_LIBRARIES}
                        ${GLIB2_LIBRARIES})

set_target_properties(kcal_caldav PROPERTIES VERSION ${KCALDAV_VERSION})

install(TARGETS kcal_caldav ${INSTALL_TARGETS_DEFAULT_ARGS})

########### next target ###############

set(kcal_caldav_plugin_PART_SRCS plugin.cpp)

kde4_add_plugin(kcal_caldav_plugin ${kcal_caldav_plugin_PART_SRCS})
# TODO: plugin and shared lib could not have the same name
if (NOT MSVC)
set_target_properties(kcal_caldav_plugin PROPERTIES OUTPUT_NAME kcal_caldav)
endif (NOT MSVC)

target_link_libraries(kcal_caldav_plugin  ${KDE4_KDECORE_LIBS} kcal_caldav ${KDEPIMLIBS_KRESOURCES_LIBS} ${KDEPIMLIBS_KCAL_LIBS})

install(TARGETS kcal_caldav_plugin  DESTINATION ${PLUGIN_INSTALL_DIR})

########### install files ###############

install(FILES ../pkg/kcal_caldav.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kresources/kcal)

